/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package org.dusin.wufang.util.jgraph;

import com.mxgraph.canvas.mxGraphics2DCanvas;

import org.dusin.wufang.graph.shape.Bianyaqi3;
import org.dusin.wufang.graph.shape.Circle;
import org.dusin.wufang.graph.shape.HBileiqi;
import org.dusin.wufang.graph.shape.HDaozha;
import org.dusin.wufang.graph.shape.HKaiguan;
import org.dusin.wufang.graph.shape.HLine;
import org.dusin.wufang.graph.shape.Huganqi;
import org.dusin.wufang.graph.shape.LDixian;
import org.dusin.wufang.graph.shape.Rectangle;
import org.dusin.wufang.graph.shape.UDixian;
import org.dusin.wufang.graph.shape.VBileiqi;
import org.dusin.wufang.graph.shape.VDaozha;
import org.dusin.wufang.graph.shape.VKaiguan;
import org.dusin.wufang.graph.shape.VLine;

/**
 *
 * @author Admin
 */
public class MyJGraphUtil {
    public static String getValue(String style, String key){
        String[] pairs = style.split(";");
        String item;
        String result=null;
        for(int i=0;i<pairs.length;i++){
            item = pairs[i];
            String[] pair = item.split("=");
            if(key.equalsIgnoreCase(pair[0])){
                result = pair[1];
            }
        }
        return result;
    }
    
    public static String setValue(String style, String key,String value){
        
        int startIndex = style.indexOf(key);
        if(startIndex==-1){
            style+=";"+key+"="+value;
        }else{
            int endIndex = style.indexOf(";", startIndex);
            if(endIndex==-1){         //该属性是最后一项，即字符串结尾
                style = style.substring(0,startIndex)+key+"="+value;
            }else{
                style = style.substring(0,startIndex)+key+"="+value+style.substring(endIndex);
            }                
        }
        return style;
    }
    
    public static void loadShape(){
        mxGraphics2DCanvas.putShape("hDaozha", new HDaozha() );
                mxGraphics2DCanvas.putShape("vDaozha", new VDaozha() );
                mxGraphics2DCanvas.putShape("vLine", new VLine() );
                mxGraphics2DCanvas.putShape("hLine", new HLine() );
                mxGraphics2DCanvas.putShape("hKaiguan", new HKaiguan() );
                mxGraphics2DCanvas.putShape("vKaiguan", new VKaiguan() );
                mxGraphics2DCanvas.putShape("lDixian", new LDixian() );
                mxGraphics2DCanvas.putShape("uDixian", new UDixian() );
                
                mxGraphics2DCanvas.putShape("huganqi", new Huganqi() );
                mxGraphics2DCanvas.putShape("bianyaqi3", new Bianyaqi3() ); 
                
                
                mxGraphics2DCanvas.putShape("hBileiqi", new HBileiqi() );
                mxGraphics2DCanvas.putShape("vBileiqi", new VBileiqi() );
                
                mxGraphics2DCanvas.putShape("circle", new Circle() );
                mxGraphics2DCanvas.putShape("rectangle", new Rectangle() ); 
                
                
    }
}
